package com.ruixinzheng.mvvmdemo.viewmodel;

import androidx.lifecycle.LiveData;
import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.ViewModel;

import com.ruixinzheng.mvvmdemo.model.MainRepo;

public class MainViewModel extends ViewModel {
    private static final String TEXT = "This is MVVM design";

    private final MutableLiveData<String> mText;
    private MainRepo mRepo;

    public MainViewModel() {
        mRepo = MainRepo.getInstance();
        mText = new MutableLiveData<>();
        mText.setValue(TEXT + " +" + mRepo.getCount());
    }

    public LiveData<String> getText() {
        return mText;
    }

    public void increaseCount() {
        int count = mRepo.increaseCount();
        mText.setValue(TEXT + " +" + count);
    }
}
